<script type="text/javascript">
function ChangeType()
{
        var type_id = $("#type").val(); 
        var url = '<?php echo osc_ajax_plugin_url("cars_attributes/ajax.php") . "&typeId="; ?>' + type_id;
        var result = ''; 						

        if ($("#type>option:selected").val() != "")
                $("#cat").val($("#type>option:selected").text());
        else 
                $("#cat").val("");

        if(type_id != '') {
            $("#make").attr('disabled',false);

            $.ajax({
                type: "POST",
                url: url,
                dataType: 'json',
                success: function(data){
                    var length = data.length;
                    if(length > 0) {
                        result += '<option value=""><?php _e("Select a make", 'cars_attributes'); ?></option>';
                        for(key in data) {
                            result += '<option value="' + data[key].pk_i_id + '">' + data[key].s_name + '</option>';
                        }
                          result += '<option value="-1"><?php _e("Others", 'cars_attributes'); ?></option>';
                          $("#makePnl").css("display","");
                          //$("#modelPnl").css("display","");
                    } else {
                        result += '<option value=""><?php _e('No results', 'cars_attributes'); ?></option>';
                         $("#model").html('<option value=""><?php _e("Select a model", 'cars_attributes'); ?></option>');
                         $("#model").attr('disabled',true);
                         $("#makePnl").css("display","none");
                         $("#modelPnl").css("display","none");
                    }
                    $("#make").html(result);
                }
             });
         } else {
            $("#make").attr('disabled',true);
            $("#model").html('<option value=""><?php _e("Select a model", 'cars_attributes'); ?></option>');
            $("#model").attr('disabled',true);
            $("#makePnl").css("display","none");
            $("#modelPnl").css("display","none");
         }
}

$(document).ready(function(){

    $("#type").change(function(){
      ChangeType();
    });
		
    $("#make").change(function(){
      var make_id = $(this).val();
        var url = '<?php echo osc_ajax_plugin_url("cars_attributes/ajax.php") . "&makeId="; ?>' + make_id;
        var result = '';
        if(make_id != '') {

            $("#model").attr('disabled',false);
            $.ajax({
                type: "POST",
                url: url,
                dataType: 'json',
                success: function(data){
                    var length = data.length;
                    if(length > 0) {
                        result += '<option value=""><?php _e("Select a model", 'cars_attributes'); ?></option>';
                        for(key in data) {
                            result += '<option value="' + data[key].pk_i_id + '">' + data[key].s_name + '</option>';
                        }
                         result += '<option value="-1"><?php _e("Others", 'cars_attributes'); ?></option>';
                         $("#modelPnl").css("display","");
                    } else {
                        result += '<option value=""><?php _e('No results', 'cars_attributes'); ?></option>';
                        $("#modelPnl").css("display","none");
                    }
                    $("#model").html(result);
                }
             });
         } else {
            $("#model").attr('disabled',true);
         }
    });

    //Select default Type
    if ($("#type>option:selected").text() != '' && $("#make").val() == '')
    {					
        ChangeType();
    }    
});
</script>
<?php 
    $make  = Params::getParam('make') ;
    $model = Params::getParam('model') ;
    $type  = Params::getParam('type') ;	
    $cat = Params::getParam('sCategory');
    $yearFrom =  Params::getParam('yearFrom') ;	
    $yearTo =  Params::getParam('yearTo') ;	
    $taxation =  Params::getParam('taxation') ;	
	
    //$makes  = ModelCars::newInstance()->getCarMakes();
    $makes = array();
	if($type != '') {
        $makes = ModelCars::newInstance()->getCarMakesByType($type);
    }
	$models = array();
    if($make != '') {
        $models = ModelCars::newInstance()->getCarModels($make);
    }

    $types = ModelCars::newInstance()->getVehiclesType(osc_current_user_locale());
	
	
?>

<fieldset>
   <fieldset id="typePnl">
        <h5><?php _e('Category', 'cars_attributes'); ?></h5>
         <div class="clearfix">
        <select name="type" id="type">
            <option value=""><?php _e('Select a car type', 'cars_attributes'); ?></option>
            <?php foreach($types as $p) { ?>
                <option value="<?php echo $p['pk_i_id']; ?>" <?php if($type==$p['pk_i_id'] || ($type == '' && $cat != '' && strcasecmp($cat,sanear_string($p['s_name']))==0)) { echo 'selected'; } ?>><?php echo $p['s_name']; ?></option>
            <?php } ?>
        </select>
         </div>
    </fieldset>
    <fieldset id="makePnl">
        <h5><?php _e('Brand or Type', 'cars_attributes'); ?></h5>
         <div class="clearfix">
        <select name="make" id="make" >
            <option value=""><?php  _e('Select a make', 'cars_attributes'); ?></option>
            <?php foreach($makes as $m) { ?>
                <option value="<?php echo $m['pk_i_id']; ?>" <?php if($make == $m['pk_i_id']) { echo 'selected'; } ?>><?php echo $m['s_name']; ?></option>
            <?php } 
            if( count($makes)>0) { ?>
            <option value="-1" <?php if($make == -1) { echo 'selected'; } ?>><?php _e('Others', 'cars_attributes'); ?></option>    
            <?php } ?>
        </select>
         </div>
    </fieldset>
    <fieldset id="modelPnl" <?php if(count($models)<=0) { echo "style='display:none;'"; } ?> >
        <h5><?php _e('Model', 'cars_attributes'); ?></h5>
         <div class="clearfix">
        <select name="model" id="model">
            <option value=""><?php _e('Select a model', 'cars_attributes'); ?></option>
            <?php foreach($models as $m) { ?>
                <option value="<?php echo $m['pk_i_id']; ?>" <?php if($model == $m['pk_i_id']) { echo 'selected';} ?>><?php echo $m['s_name']; ?></option>
            <?php }
            if( count($models)>0) { ?>
             <option value="-1" <?php if($model == -1) { echo 'selected'; } ?>><?php _e('Others', 'cars_attributes'); ?></option>    
             <?php } ?>
        </select>
         </div>
    </fieldset>	
    
    <fieldset id="taxationPnl">
        <h5><?php _e('Category Allowed Taxation', 'cars_attributes'); ?></h5>
         <div class="clearfix">
                <select name="taxation" id="taxation">
                    <option value=""><?php _e('Select allowed drive taxation', 'cars_attributes'); ?></option>
                    <option value="privatecompany" <?php if($taxation == 'privatecompany') { echo 'selected'; } ?>><?php _e('Private & Company', 'cars_attributes'); ?></option>
                    <option value="companysonly" <?php if($taxation == 'companysonly') { echo 'selected'; } ?>><?php _e('Companys Only', 'cars_attributes'); ?></option>
                    <option value="norestrictions" <?php if($taxation == 'norestrictions') { echo 'selected'; } ?>><?php _e('No restrictions', 'cars_attributes'); ?></option>
                    <option value="private" <?php if($taxation == 'private') { echo 'selected'; } ?>><?php _e('Private', 'cars_attributes'); ?></option>
                 </select>
         </div>
        </fieldset>
	
	<fieldset>           
		<div style="display:inline-block;width:100%;margin-top:10px;">
		<div style="float:left;">
                    <p style="font-size: 14px;font-weight: bold;"><?php _e('Year from', 'cars_attributes') ; ?></p>
                    
                    <input type="text" id="yearFrom" name="yearFrom" value="<?php if($yearFrom != '') echo $yearFrom; ?>" size="6" maxlength="6" />	
		</div>
                <div style="float:right;">
                     <p style="font-size: 14px;font-weight: bold;"><?php _e('Year to', 'cars_attributes') ; ?></p>
                     <input type="text" id="yearTo" name="yearTo" value="<?php if ($yearTo != '') echo $yearTo; ?>" size="6" maxlength="4" />
                </div>
		</div>		
	</fieldset>		
	
	
    <!--<div class="row one_input" style="display:none;">
        <?php //$transmission = Params::getParam('transmission') ; ?>
        <h6 for="transmission"><?php //_e('Transmission', 'cars_attributes'); ?></h6>
        <input style="width:20px;" type="radio" name="transmission" value="MANUAL" id="manual" <?php //if($transmission == 'MANUAL') { echo 'checked="yes"'; } ?>/> <label for="manual"><?php //_e('Manual', 'cars_attributes'); ?></label><br />
        <input style="width:20px;" type="radio" name="transmission" value="AUTO" id="auto" <?php //if($transmission == 'AUTO') { echo 'checked="yes"'; } ?>/> <label for="auto"><?php //_e('Automatic', 'cars_attributes'); ?></label>
    </div>-->
</fieldset>